//
//  GamesTableViewCell.m
//  LPSNews
//
//  Created by lanou3g on 14-10-11.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "GamesTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation GamesTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        //标题
        UILabel * titleLabel = [[UILabel alloc]init];
        self.titleLabel = titleLabel;
        [self.contentView addSubview:titleLabel];
        [titleLabel release];
        //摘要
        UILabel * digestLabel = [[UILabel alloc]init];
        self.digestLabel = digestLabel;
        [self.contentView addSubview:digestLabel];
        [digestLabel release];
        //图片
        UIImageView * newsImageView = [[UIImageView alloc]init];
        self.newsImageView = newsImageView;
        [self.contentView addSubview:newsImageView];
        [newsImageView release];
        //底部的线
        UIView * bottomLine = [[UIView alloc]init];
        self.bottomLine = bottomLine;
        [self.contentView addSubview:bottomLine];
        [bottomLine release];

    }
    return self;
}
- (void)setGames:(Games *)games
{
    //下载图片
     [self.newsImageView sd_setImageWithURL:[NSURL URLWithString:games.imgsrc] placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];
       if (games.number == 0) {
        //图片
        self.newsImageView.frame = CGRectMake(0, 0, self.frame.size.width, 185);
        //标题
        self.titleLabel.frame = CGRectMake(10, CGRectGetMaxY(self.newsImageView.frame)+1,[UIScreen mainScreen].bounds.size.width-20,25);
        self.titleLabel.text = games.title;
        self.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    else{
        //图片
        CGPoint tempoint = CGPointMake(10, 9.75);
        CGSize size = CGSizeMake(88.64, 65);
        self.newsImageView.frame = (CGRect){tempoint,size};
        self.newsImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.newsImageView.clipsToBounds = YES;
        //标题
        self.titleLabel.text = games.title;
        self.titleLabel.font = [UIFont systemFontOfSize:14.5];
        self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.newsImageView.frame) + 10, 10, [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.newsImageView.frame), 20);
        //摘要
        self.digestLabel.text = games.digest;
        self.digestLabel.frame = CGRectMake(CGRectGetMaxX(self.newsImageView.frame) + 10, CGRectGetMaxY(self.titleLabel.frame), [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.newsImageView.frame) -10 ,50);
        self.digestLabel.font = [UIFont systemFontOfSize:13];
        self.digestLabel.textColor = [UIColor darkGrayColor];
        self.digestLabel.numberOfLines = 0;
        self.digestLabel.lineBreakMode = NSLineBreakByWordWrapping;
        // 底部的线
        self.bottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
        self.bottomLine.frame = CGRectMake(0, CGRectGetMaxY(self.newsImageView.frame)+ 9.50, [UIScreen mainScreen].bounds.size.width, 0.75);
    }
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
